package com.ztt.controller.admin;

import com.ztt.pojo.entity.zttPurchase;
import com.ztt.service.PurchaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class PurchaseController {
    @Autowired
    public PurchaseService purchaseService;


    @GetMapping("/selectAllPurchase")
    public List<zttPurchase> selectAllPurchase(){
        return purchaseService.selectAllPurchase();
    }


    @PostMapping("/insertPurchase")
    public void insertPurchase(@RequestBody zttPurchase purchase){
        purchaseService.insertPurchase(purchase);
    };

    @PostMapping("/getPurchaseById")
    public zttPurchase getPurchaseById(@RequestBody zttPurchase purchase) {
        return purchaseService.getPurchaseById(purchase);
    }


    @PostMapping("/getPurchaseByEmployeeId")
    public List<zttPurchase> getPurchaseByEmployeeId(@RequestBody zttPurchase purchase) {
        return purchaseService.getPurchaseByEmployeeId(purchase);
    }


    @PostMapping("/updatePurchase")
    public void updatePurchase(@RequestBody zttPurchase purchase) {
        purchaseService.updatePurchase(purchase);
    }


    @PostMapping("/deletePurchase")
    public String deletePurchase(@RequestBody zttPurchase purchase) {
        try{
            purchaseService.deletePurchase(purchase);
            return "success";
        }catch (Exception e){
            e.printStackTrace();

            return "error";
        }
    }

}
